package com.hmdp.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

import lombok.extern.slf4j.Slf4j;

/**
 * 用户登录拦截器
 * 
 * @author 17452
 *
 */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

		log.debug("加载用户登录拦截器");

		// 1.判断ThreadLocal中是否有用户
		if (UserHolder.getUser() == null) {
			response.setStatus(401);
			return false;
		}
		return true;
	}

}
